import $ from 'zepto'

export default function (router) {
  router.map({
    '*': {
      component (resolve) {
        require(['./views/home'], resolve)
      }
    },
    '/': {
      component (resolve) {
        require(['./views/home'], resolve)
      }
    },
    '/home': {
      component (resolve) {
        require(['./views/home'], resolve)
      }
    },
    '/ucenter': {
      component (resolve) {
        require(['./views/ucenter'], resolve)
      }
    },
    '/bill/:type': {
      component (resolve) {
        require(['./views/bill'], resolve)
      }
    },
    '/buhege': {
      component (resolve) {
        require(['./views/buhege'], resolve)
      }
    },
    '/chongzhi': {
      component (resolve) {
        require(['./views/chongzhi'], resolve)
      }
    },
    '/jiapiao/:taskId/:type': {
      component (resolve) {
        require(['./views/jiapiao'], resolve)
      }
    },
    '/kaishizhuan': {
      component (resolve) {
        require(['./views/kaishizhuan'], resolve)
      }
    },
    '/liuyanjuti': {
      component (resolve) {
        require(['./views/liuyanjuti'], resolve)
      }
    },
    '/look_img/:taskId': {
      component (resolve) {
        require(['./views/look_img'], resolve)
      }
    },
    '/buhegeimg/:taskId': {
      component (resolve) {
        require(['./views/buhegeimg'], resolve)
      }
    },
    '/message': {
      component (resolve) {
        require(['./views/message'], resolve)
      }
    },
    '/publish_task': {
      component (resolve) {
        require(['./views/publish_task'], resolve)
      }
    },
    '/rebuild_primary': {
      component (resolve) {
        require(['./views/rebuild_primary'], resolve)
      }
    },
    '/rebuild_mid': {
      component (resolve) {
        require(['./views/rebuild_mid'], resolve)
      }
    },
    '/rebuild_high': {
      component (resolve) {
        require(['./views/rebuild_high'], resolve)
      }
    },
    '/rebuild_read': {
      component (resolve) {
        require(['./views/rebuild_read'], resolve)
      }
    },
    '/rebuild_repeat': {
      component (resolve) {
        require(['./views/rebuild_repeat'], resolve)
      }
    },
    '/rebuild_task': {
      component (resolve) {
        require(['./views/rebuild_task'], resolve)
      }
    },
    '/rebuild_third': {
      component (resolve) {
        require(['./views/rebuild_third'], resolve)
      }
    },
    '/rebuild_upvote': {
      component (resolve) {
        require(['./views/rebuild_upvote'], resolve)
      }
    },
    '/rebuild_attention': {
      component (resolve) {
        require(['./views/rebuild_attention'], resolve)
      }
    },
    '/regist': {
      component (resolve) {
        require(['./views/regist'], resolve)
      }
    },
    '/shenhe/:taskId': {
      component (resolve) {
        require(['./views/shenhe'], resolve)
      }
    },
    '/sys_news': {
      component (resolve) {
        require(['./views/sys_news'], resolve)
      }
    },
    '/task_details/:taskId': {
      component (resolve) {
        require(['./views/task_details'], resolve)
      }
    },
    '/tixian': {
      component (resolve) {
        require(['./views/tixian'], resolve)
      }
    },
    '/toupiao': {
      component (resolve) {
        require(['./views/toupiao'], resolve)
      }
    },
    '/tuijianma': {
      component (resolve) {
        require(['./views/tuijianma'], resolve)
      }
    },
    '/xinshoujiaocheng': {
      component (resolve) {
        require(['./views/xinshoujiaocheng'], resolve)
      }
    },
    '/yongjin': {
      component (resolve) {
        require(['./views/yongjin'], resolve)
      }
    },
    '/upload/:taskId/:customerTaskId': {
      component (resolve) {
        require(['./views/upload'], resolve)
      }
    }
  })

  router.beforeEach(({to, from, next}) => {
    let toPath = to.path
    let fromPath = from.path
    console.log(`to: ${toPath} from: ${fromPath}`)
    if (toPath.replace(/[^/]/g, '').length > 1) {
      router.app.isIndex = false
    }
    else {
      let depath = toPath === '/' || toPath === '/home'
      router.app.isIndex = depath ? 0 : 1
    }
    next()
  })

  router.afterEach(function ({to}) {
    console.log(`成功浏览到: ${to.path}`)
    $.refreshScroller()
  })
}
